<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<script>
    let count = 0;
    let timer = setInterval(f, 1000)

    function f() {
        count++;
        let h1 = document.querySelector("h1")
        h1.innerText = count;
        if (count == 5) {
            clearInterval(timer);
        }
    }

    // //匿名方法开启定时器
    // setInterval(function () {
    //     console.log(count)
    // }, 1000);
    e
    //开启只执行一次的定时器
    setTimeout(function () {
        alert(location.href);
        location.href="http://www.baidu.com"
    }, 3000)
</script>
</body>
</html>